package com.ych.rabbitmq.exchange;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/3/11
 * Time: 14:15
 * Description:
 */
@Configuration
public class UserRechargeOrderExchange {
    /**
     * 当前变量与类同名
     */
    public final static String CLASSNAME = "UserRechargeOrderExchange";

    /**
     * 以下不必修改
     */
    private final static String _DELAY_EXCHANGE = CLASSNAME + "_delay_exchange";
    private final static String _DELAY_QUEUE    = CLASSNAME + "_delay_queue";
    //交换机名
    public final static  String EXCHANGE_NAME   = _DELAY_EXCHANGE;
    //队列名
    public final static  String QUEUE_NAME      = _DELAY_QUEUE;

    @Bean(CLASSNAME + "CustomExchange")
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(_DELAY_EXCHANGE, "x-delayed-message", true, false, args);
    }

    @Bean(CLASSNAME + "Queue")
    public Queue queue() {
        Queue queue = new Queue(_DELAY_QUEUE, true);
        return queue;
    }

    @Bean(CLASSNAME + "Binding")
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(customExchange()).with(_DELAY_QUEUE).noargs();
    }

}
